package com.party.controller.api;


import com.party.common.base.ApiResult;
import com.party.common.entity.MyPage;
import com.party.entity.PbResource;
import com.party.entity.dto.DistributeDto;
import com.party.entity.dto.QueryResourceDto;
import com.party.service.PbResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 资源 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-10-25
 */
@RestController
@RequestMapping("api/pb-resource")
@Api(tags = "资源api接口", value = "资源api接口")
public class PbResourceController {

    @Resource
    private PbResourceService pbResourceService;

    @PostMapping("add")
    @ApiOperation("保存")
    public ApiResult add(@RequestBody PbResource pbResource){
        return ApiResult.ok(pbResourceService.add(pbResource));

    }

    @PostMapping("update")
    @ApiOperation("编辑")
    public ApiResult update(@RequestBody PbResource pbResource){
        return ApiResult.ok(pbResourceService.edit(pbResource));
    }

    @GetMapping("delete")
    @ApiOperation("删除")
    public ApiResult delete(Long id){
        return ApiResult.ok(pbResourceService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询")
    public ApiResult<MyPage<PbResource>> queryPage(@RequestBody QueryResourceDto dto){
        MyPage<PbResource> page = pbResourceService.queryPage(dto);
        return ApiResult.ok(page);
    }

    @GetMapping("detail")
    @ApiOperation(value = "详情",response = PbResource.class)
    public ApiResult detail(Long id){
        return ApiResult.ok(pbResourceService.detail(id));
    }

    @GetMapping("like")
    @ApiOperation(value = "点赞",response = Boolean.class)
    public ApiResult<Boolean> like(Long id,Integer likeCount){
        return ApiResult.ok(pbResourceService.like(id,likeCount));
    }

    @GetMapping("upAndDown")
    @ApiOperation(value = "上架/下架",response = Boolean.class)
    public ApiResult<Boolean> upAndDown(Long id){
        return ApiResult.ok(pbResourceService.upAndDown(id));
    }

    @GetMapping("synchronous")
    @ApiOperation(value = "同步中台数据",response = ApiResult.class)
    public ApiResult synchronous(){
        return ApiResult.ok(pbResourceService.synchronous());
    }

    @GetMapping("recommend")
    @ApiOperation(value = "推荐(取消推荐) 参数设备id 、资源id",response = Boolean.class)
    public ApiResult<Boolean> recommend(String deviceId,String resourceId){
        return ApiResult.ok(pbResourceService.recommend(deviceId,resourceId));
    }

}

